package com.macro.utils;

import org.springframework.stereotype.Component;

import java.io.File;
import java.io.FileOutputStream;
import java.util.UUID;

@Component
public class BytesToFileUtil {
    /**
     * byte[] 转文件
     *
     * @param data
     * @param file
     */
    public static void genFile(byte[] data, File file) {
//        if (CheckUtils.isNull(data) || data.length < 3 || CheckUtils.isNull(file))
//            return;
        try (FileOutputStream fio = new FileOutputStream(file)) {
            fio.write(data, 0, data.length);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
    public static  String CreateFileName(String url){
        String name = UUID.randomUUID().toString().replaceAll("-","");
        int i = url.indexOf(".");
        String type = url.substring(i, url.length());
        System.out.println(type);
        String fileName=name+""+type;
        System.out.println(fileName);
        return fileName;
    }
   /* public static void main(String[] args) {
        BytesToFileUtil.CreateFileName("group1/M00/00/00/wKjIgGKh0rKAHUVfAAWvSenGfG4293.jpg");
    }*/


}
